package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/09/28 21:03
 **/
public class Day27_1_Op17_09_GetKthMagicNumber {
    class Solution {
        public int getKthMagicNumber(int k) {
            int[] dp = new int[k];
            dp[0] = 1;
            int ind3 = 0, ind5 = 0, ind7 = 0;
            int res;
            for(int i = 1; i < k; ++i){
                res = Math.min(dp[ind3] * 3, Math.min(dp[ind5] * 5, dp[ind7]*7));
                if(res % 3 == 0) ind3++;
                if(res % 5 == 0) ind5++;
                if(res % 7 == 0) ind7++;
                dp[i] = res;
            }
            return dp[k-1];
        }
    }
}